<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../lib/index.js"></script>
</head>
<body>
<canvas id="canvas" width="400" height="400" style="background: gray">
    此浏览器不支持canvas
</canvas>
</body>
</html>

<script>
    const ctx = document.getElementById('canvas')
    const gl = ctx.getContext('webgl')

    // step1: 创建着色器源码
    // 顶点着色器
    const VERTEX_SHADER_SOURCE = `
        attribute vec4 aPosition; // 声明变量的语法结构
        void main() {
            gl_Position = aPosition;
            gl_PointSize = 30.0;
        }
`
    // 片元着色器
    const FRAGMENT_SHADER_SOURCE = `
        void main() {
            gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); // 这里的分号不能丢
        }
    `
    // step2: 公用方法
    const program = initShader(gl, VERTEX_SHADER_SOURCE, FRAGMENT_SHADER_SOURCE)

    // step3: 获取attribute变量
    const aPosition = gl.getAttribLocation(program, 'aPosition');

    // step4: 给 attribute 变量赋值
    gl.vertexAttrib4f(aPosition, 0.5, 0.5, 0.0, 1.0);

    // step5: 执行绘制
    gl.drawArrays(gl.POINTS, 0, 1) // 绘制点

</script>
